package com.mgface.framework.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project ms-mgface-framework-springcloud
 * @create 2017-04-13 23:29
 **/
@RestController
public class ApplicationController {
	@Autowired
	private EurekaClient eurekaClient;

	@Autowired
	private DiscoveryClient discoveryClient;

	@GetMapping("/get-eureka-instance/{instance}")
	public InstanceInfo serviceUrl(@PathVariable("instance") String instance) {
		//InstanceInfo instanceInfo = this.eurekaClient.getNextServerFromEureka("MS-DISCOVERY-USER", false);
		InstanceInfo instanceInfo = this.eurekaClient.getNextServerFromEureka(instance, false);
		return instanceInfo;
	}

	@GetMapping("/current-instance-info")
	public ServiceInstance showInfo() {
		ServiceInstance localServiceInstance = this.discoveryClient.getLocalServiceInstance();
		return localServiceInstance;
	}
}
